package items;

import java.util.ArrayList;

public class RankingList 
{
	private ArrayList<RankingItem> lRI;
	
	public RankingList()
	{
		lRI = new ArrayList<RankingItem>();
	}
	
	public void add( RankingItem ri )
	{
		int i=buscaPrimero(ri.getTabla());
		int f=buscaUltimo(ri.getTabla())+1;
		if( i==-1 )//Primer elemento de esa tabla
			lRI.add(ri);
		else
		{
			boolean t=false;
			while(!t&&i<f)
			{
				t = ri.getNota()>lRI.get(i).getNota();
				i++;
			}
			if(t)
				lRI.add(i-1,ri);
			else
				lRI.add(i,ri);
		}
	}
	
	private int buscaUltimo(String tabla)
	{
		for( int i=lRI.size()-1 ; i>-1 ; i-- )
			if( lRI.get(i).getTabla().equalsIgnoreCase(tabla) )
				return i;
		return -1;
	}
	
	private int buscaPrimero(String tabla)
	{
		for( int i=0 ; i<lRI.size() ; i++ )
			if( lRI.get(i).getTabla().equalsIgnoreCase(tabla) )
				return i;
		return -1;
	}
	
	public int size()
	{
		return lRI.size();
	}
	
	public int length()
	{
		return lRI.size();
	}
	
	public RankingItem get(int i)
	{
		return lRI.get(i);
	}
}
